import { request } from '@umijs/max';
// type QueryData ={
//   name?: string
// }

/**
 *
 * @returns 获取文章数据
 */
// QueryData & {pageSize: number;current: number;}
export const loadDataAPI = async (params: any) => {
  // console.log(params);
  const res = await request('/admin/article_categories', {
    method: 'GET',
    params: {
      name: params.name, //查询条件
      per:params.per, //每页显示的数量
      page:params.current, //页码
    },
  });
  console.log(res);
  return {
    data: res.data.list,
    // success 请返回 true，
    // 不然 table 会停止解析数据，即使有数据
    success: true,
    // 不传会使用 data 的长度，如果是分页一定要传
    total: res.data.total,
  };
};



/**
 * 
 * @returns 获取100条数据
 */

export const loadAllDataAPI = ()=>{
  return request ('/admin/article_categories',{
    method: 'GET',
    params:{
      per:100,
    }
  })
}
/***
 * 新增
 */
export  const createOneAPI =async(data: any)=>{
return request ('/admin/article_categories',{
  method: 'POST',
  data
})
}

/**
 * 
 * @param id 根据id修改
 * @param data 
 * @returns 
 */

export const  updataByIdAPI = (id: string,data: any)=>{
  return request ('/admin/article_categories/'+id,{ 
    method:"PATCH",
    data,
  })
}

/**
 * 
 * @param id 根据id删除
 * @returns 
 */

export const delByIdAPI = (id: string)=>{
  return request ('/admin/article_categories/'+id,{
    method:'DELETE'
  })
}


/**
 * 
 * @param id 根据id获取单个文章数据
 * @returns 
 */
export const loadByIdAPI = (id: string)=>{
  return request ('/admin/article_categories/'+id,{
    method:'GET'
  })
}


/**
 * 批量删除
 */
export const deleteManyAPI =(ids: string) =>{
  return request('/admin/article_categories/remove_many?ids='+ids,{
    method:"DELETE"
  })
}